blob: c7b0cead360314e673aec02dea96f989bfb27ec6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import { View } from "react-native";
import { Stack, useLocalSearchParams } from "expo-router";
import BookmarkAssetImage from "@/components/bookmarks/BookmarkAssetImage";
import BookmarkTextMarkdown from "@/components/bookmarks/BookmarkTextMarkdown";
import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
import PageTitle from "@/components/ui/PageTitle";
import { api } from "@/lib/trpc";
import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks";
function BookmarkTextView({ bookmark }: { bookmark: ZBookmark }) {
if (bookmark.content.type !== BookmarkTypes.TEXT) {
throw new Error("Wrong content type rendered");
}
const content = bookmark.content.text;
return (
<View className="flex gap-2">
<BookmarkTextMarkdown text={content} />
</View>
);
}
function BookmarkAssetView({ bookmark }: { bookmark: ZBookmark }) {
if (bookmark.content.type !== BookmarkTypes.ASSET) {
throw new Error("Wrong content type rendered");
}
return (
<View className="flex gap-2">
<BookmarkAssetImage
assetId={bookmark.content.assetId}
className="h-56 min-h-56 w-full object-cover"
/>
</View>
);
}
export default function BookmarkView() {
const { slug } = useLocalSearchParams();
if (typeof slug !== "string") {
throw new Error("Unexpected param type");
}
const { data: bookmark } = api.bookmarks.getBookmark.useQuery({
bookmarkId: slug,
});
let comp;
let title = null;
if (bookmark) {
switch (bookmark.content.type) {
case BookmarkTypes.LINK:
comp = null;
break;
case BookmarkTypes.TEXT:
title = bookmark.title;
comp = <BookmarkTextView bookmark={bookmark} />;
break;
case BookmarkTypes.ASSET:
title = bookmark.title ?? bookmark.content.fileName;
comp = <BookmarkAssetView bookmark={bookmark} />;
break;
}
} else {
comp = <FullPageSpinner />;
}
return (
<CustomSafeAreaView>
<Stack.Screen
options={{
headerTitle: "",
headerBackTitle: "Back",
headerTransparent: true,
}}
/>
<PageTitle title={title ?? "Untitled"} />
<View className="px-4 py-2">{comp}</View>
</CustomSafeAreaView>
);
}
|